Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Introduction to Sigslots
Description: Creating, connecting and triggering signals and slots.Keywords: ecl sigslots
Tutorial Level: INTERMEDIATE
Next Tutorial: Relaying Signals Debugging Sigslots
Slot Loading
Loading of slots can be done directly to free or member functions through the constructors. Below is a simple example for various types of loading.
Connecting
Signals and slots have no limit to the number of connections they may make.
Emitting
Every time a signal emits, the connected slots are consecutively run with the data that is emitted.
Every emit, the slots are consecutively run - this means that your slots should by nature be short and concise! Otherwise you'll get serious bottlenecks. This is always a good habit to get into for slots otherwise you'll frequently run into problems. If you have a heavy callback, consider spinning that callback off into a thread. That way the thread response will still be quick (cost of a thread creation) and you can still manage heavy workloads.
Design Considerations
- Keep your slot callbacks concise...failing that, reference them or spin the work off into a thread!
- For data slots use const references, saves a copy and prevents your original class losing control of its variables.
- Slots w/ member functions should be member variables of the same class, this guarantees the function is always valid.
- The sigslots manager may become a bottleneck if you are creating/connecting/disconnecting a large number of slots.
- If you do need a sigslot implementation that can handle massive numbers of sigslots, fast connection and disconnection, then you probably need to look at the old ecl signals or boost/qt. At the moment, we can't foresee a need for that in
control systems, but if needed, this library can be extended.